package com.lzt.admin.common.utils;

import cn.hutool.core.convert.Convert;

import java.util.Arrays;

public class ConverUtil {
    public static Boolean toBool(Object value) {
        return toBool(value, null);
    }

    public static Boolean toBool(Object value, Boolean defaultValue) {
        if (value == null) {
            return defaultValue;
        }
        if (value instanceof Boolean) {
            return (Boolean) value;
        }
        String valueStr = Convert.toStr(value).replace("\"", "").trim().toLowerCase();
        String[] arr = {"true", "yes", "ok", "1"};
        return Arrays.stream(arr).anyMatch(n -> n.equals(valueStr));
    }
}
